grsecurity: GRKERNSEC_PERF_HARDEN
authorBen Hutchings <ben@decadent.org.uk>
Thu, 17 Mar 2016 01:25:23 +0000 (01:25 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 17 Mar 2016 01:25:23 +0000 (01:25 +0000)
The GRKERNSEC_PERF_HARDEN feature extracted from grsecurity.  Adds the
option to disable perf_event_open() entirely for unprivileged users.
This standalone version doesn't include making the variable read-only
(or renaming it).

Gbp-Pq: Topic features/all/grsecurity
Gbp-Pq: Name grkernsec_perf_harden.patch

grsecurity/Kconfig
include/linux/perf_event.h
kernel/events/core.c

index 193d20992d2b73ccd9cafd08073fcfab0299934b..7a685bc7b7dd4741b5a0cd90752a96eb235391c9 100644 (file)
@@ -1,3 +1,21 @@
 #
 # grecurity configuration
 #
+config GRKERNSEC_PERF_HARDEN
+       bool "Disable unprivileged PERF_EVENTS usage by default"
+       depends on PERF_EVENTS
+       help
+         If you say Y here, the range of acceptable values for the
+         /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
+         default to a new value: 3.  When the sysctl is set to this value, no
+         unprivileged use of the PERF_EVENTS syscall interface will be permitted.
+
+         Though PERF_EVENTS can be used legitimately for performance monitoring
+         and low-level application profiling, it is forced on regardless of
+         configuration, has been at fault for several vulnerabilities, and
+         creates new opportunities for side channels and other information leaks.
+
+         This feature puts PERF_EVENTS into a secure default state and permits
+         the administrator to change out of it temporarily if unprivileged
+         application profiling is needed.
+
index f9828a48f16addab4737683f3c8345ab87e52a0a..aa7294092e51c129a714a27d09978a57fab7117b 100644 (file)
@@ -989,6 +989,11 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
                loff_t *ppos);
 
 
+static inline bool perf_paranoid_any(void)
+{
+       return sysctl_perf_event_paranoid > 2;
+}
+
 static inline bool perf_paranoid_tracepoint_raw(void)
 {
        return sysctl_perf_event_paranoid > -1;
index 1087bbeb152b101f5f20d61bac075a0f88f28944..3dcc78be880eb351d80c9fa27d61784ae918adf3 100644 (file)
@@ -175,8 +175,13 @@ static struct srcu_struct pmus_srcu;
  *   0 - disallow raw tracepoint access for unpriv
  *   1 - disallow cpu events for unpriv
  *   2 - disallow kernel profiling for unpriv
+ *   3 - disallow all unpriv perf event use
  */
+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
+int sysctl_perf_event_paranoid __read_mostly = 3;
+#else
 int sysctl_perf_event_paranoid __read_mostly = 1;
+#endif
 
 /* Minimum for 512 kiB + 1 user control page */
 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
@@ -8265,6 +8270,11 @@ SYSCALL_DEFINE5(perf_event_open,
        if (flags & ~PERF_FLAG_ALL)
                return -EINVAL;
 
+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
+       if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
+               return -EACCES;
+#endif
+
        err = perf_copy_attr(attr_uptr, &attr);
        if (err)
                return err;